let user = localStorage.user && JSON.parse(localStorage.user)
let body = document.querySelector('.main-ul')
let dropdown = document.querySelector('.dropdown-lift')
let dropdowns = document.querySelector('.dropdown-right')
let del1  = document.querySelector('.del1')
let del2  = document.querySelector('.del2')


//发送请求，获取用户数据
renderContents()
async function renderContents(){
    let res = await axios({
        method:'get',
        url:'/api/user',
        params:{
            userId:user.userId
            // userId: "632595e0e24deb53641c4b2b"
        }
    })
    //渲染数据
    console.log(res.data.data);
    let data = res.data.data

    //我的
    renderUserList2(data) 
    function renderUserList2(data) {
    let reminds = '';
        reminds +=`
        <a href="" class="title">${data.username}</a>
        <span class="caret"></span>
        <ul class="userdisplay">
            <li>
                <a href="../lk/my-diary.html">我的日记</a>
            </li>
            <li>
                <a href="guanzhudereng.html">我关注的人</a>
            </li>
            <li>
                <a href="">设置</a>
            </li>
            <li>
                <a href="../dc/login.html">退出</a>
            </li>
        </ul>
        `
    dropdowns.innerHTML = reminds
}

//提醒
renderContents1()
async function renderContents1(){
    let res3 = await axios({
        method:'get',
        url:'/api/reply',
        params:{
            userId:user.userId
            // userId: "632595e0e24deb53641c4b2b"
        }
    })
        // 渲染数据
        let data = res3
        console.log(data);
        renderUserList1(res)
        function renderUserList1(res) {
            let remind = '';
                remind +=`
                    <a href="tixing.html" class="title">提醒(${0})</a>
                    <span class="caret"></span>
                    <ul class="msg">
                        <li>没有提醒</li>
                    </ul>
                `
            dropdown.innerHTML = remind
            }
    }
    
    // 发送请求，获取回复数据
renderContents5()
async function renderContents5(){
    let res1 = await axios({
        method:'get',
        url:'/api/reply',
        params:{
            userId:user.userId
        }
    })
    
    let data = res1.data.data
    // for (const item of ) {
        
    // }
    renderContents()
    async function renderContents(){
        let res2 = await axios({
            method:'get',
            url:'/api/user',
            params:{
                userId:user.userId
            }
        })
    //渲染数据
    let data = res1.data.data
    
    let data1 = res2.data.data
    
    console.log(data);
    if(data.length == 0){
        return
    }else{
        let html = '';
        html += `
                <li class = "item"
                    <span>${data1.username}</span>
                    <a class="return" href="">回复了你</a>
                    <a class="cha" href="">[×]</a>
                </li>
                `    
        del1.innerHTML = html
    }
    // let replay = document.querySelector('.cha')
}}


//  发送请求，获取关注数据
 renderContents2()
 async function renderContents2(){
     let res3 = await axios({
         method:'get',
         url:'/api/user',
         params:{
            userId:user.userId
         }
     })
     //渲染数据
     let data = res3.data.data.fansId
     console.log(data);
     if(data == null ){
            let html = '';
            html += `
                    <li class = "item">
                        <a class="return" href="">没有提醒</a>
                    </li>
                    `    
            del1.innerHTML = html
        }else{
            let html = '';
            for (const item of data) {
                console.log(item);
                renderContents()
                async function renderContents(){
                    let res2 = await axios({
                        method:'get',
                        url:'/api/user',
                        params:{
                            userId:item
                        }
                    })
                    console.log(999,res2.data.data);
                    let data2 = res2.data.data
                html += `
                        <a href="" class="name">${data2.username}</a>
                        <a class="you" href="">关注了你</a>
                        <a class="cha" href="">[×]</a>
                        `
                        del2.innerHTML = html
                }
            }   
    } 
 }


// replay.onclick = async function (e){
//     if (!e.target.matches('.delete')) return

// 			// 获取到需要删除的账户名
// 			let account = e.target.dataset.account;

// 			// 发起请求，删除账户
// 			let res = await ajax({
// 				method: 'delete',
// 				url: `/api/users/${account}`
// 			})
//     e.target.closest('.item').remove();
// }
}
